package de.rj.urwalking.ui.fragments.dialog;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import de.rj.urwalking.R;
import de.rj.urwalking.config.Constants;
import de.rj.urwalking.data.Poi;
import de.rj.urwalking.db.DBSalientObject;
import de.rj.urwalking.ui.activities.QuestionsActivity;
import de.rj.urwalking.util.PrefUtil;

public class PoiDialogFragment extends LandmarkDialogFragment implements OnClickListener {

	private Poi poi;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = super.onCreateView(inflater, container, savedInstanceState);

		poi = (Poi) getArguments().getSerializable("object");
		if (poi.hasUserDefinedName()) {
			getDialog().setTitle(poi.getUserDefinedName());
		} else {
			getDialog().setTitle(getResources().getString(R.string.poi));
		}

		if (PrefUtil.readBoolean(R.string.key_pref_show_landmarks, getActivity(), false)) {
			showMoreInfo(poi);
		} else {
			hideInfoView();
		}

		return view;
	}

	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.suggestButton:
			ensureExperiment();
			Intent intent = new Intent(getActivity(), QuestionsActivity.class);
			intent.putExtra("object", new DBSalientObject(null, poi.getOsmId(), null, null, null, null, null));
			startQuestions(intent);
			this.dismiss();
			break;
		case R.id.backButton:
			this.dismiss();
			break;
		default:
			break;
		}

	}
}
